<template>
  <div class="excitingActivity" ref="homePage">
    <div class="bj">
      <van-nav-bar @click-left="clickleft" style="background: white;position: fixed;width: 100%;" title="活动日历" left-text="" left-arrow></van-nav-bar>
    </div>
    <div style="height: 110px;width: 100%;"></div>
    <div style="height: 60px;display: flex;align-items: center;position: fixed;width: 100%;top:46px;background: #46d0ca;z-index: 99;">
      <div class="search">
        <div @click="select" class="search_cs">
          <span>{{current}}</span>
          <van-icon name="arrow-down" />
        </div>
        <div class="search_in">
          <form action="/">
            <van-search placeholder="搜索想要的旅游产品或服务" v-model="search_value" @search="issuecontent" />
          </form>
        </div>
      </div>
    </div>
    <van-popup position="" style="width: 100%;height: 100%;position: absolute;top: 0;" v-model="show">
      <van-nav-bar title="城市列表" left-arrow @click-left="onClickLeft" />
      <div class="current">
        <div class="current_box">
          <span>当前城市</span>
          <span style="color: #00CBA6;">{{current}}</span>
        </div>
        <div class="current_box">
          <span>定位城市</span>
          <span style="color: #00CBA6;display: flex;align-items: center;">
            <van-icon name="location" size="16px" />{{chengshi}}</span>
        </div>
      </div>
      <div class="popular">
        <p class="popular_p">热门城市</p>
        <div style="display: flex;flex-wrap: wrap;justify-content: space-around;">
          <div @click="popularCs(item)" class="popular_cs" v-for="(item,index) in Popular" :key='index'>{{item}}</div>
        </div>
      </div>
      <van-index-bar :index-list="nameData">
        <div v-for="(data,index) in ityList" :key="index">
          <van-index-anchor :index="data.id">{{data.name}}</van-index-anchor>
          <van-cell @click="cell(res.name)" v-for="(res,index) in data.content" :key="index" :title="res.name" />
        </div>
      </van-index-bar>
    </van-popup>

    <div>
      <div v-show="datalist.length == 0" class="wudingdan">
        <van-icon name="description" />
        <p>亲,暂无相关数据哦</p>
      </div>
      <div v-show="datalist.length != 0" class="list">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
          <div class="performance-item" @click="Jumpbuy(itme.resSN,'活动日历')" v-for="(itme,index) in datalist" :key="index">
            <div class="img-box">
              <img height="100%" :src="itme.Cover" />
            </div>
            <div class="info-box">
              <p class="title">{{itme.Name}}</p>
              <div class="intro">{{itme.Info}}</div>
              <p class="price">￥{{itme.Price}}</p>
              <van-button style="position: absolute;bottom: 0.3125rem;min-width: 90px;" type="default" size="small" color="#46d0ca">立即购买</van-button>
            </div>
          </div>
        </van-list>
      </div>
    </div>
  </div>
</template>

<script>
import city from '@/assets/js/city.js'
import AMap from 'AMap'
import {
  resourceList
} from '@/api/home.js'
export default {
  components: {

    // "v-search": search,
  },
  data () {
    return {
      clintHeigth: '', // 获取页面高度
      active: 0,
      show: false,
      chengshi: '', // 定位
      current: '', // 选择城市
      search_value: '',
      nameData: [
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
        'W',
        'X', 'Y', 'Z'
      ],
      Popular: ['上海', '北京', '广州', '深圳', '武汉', '天津', '西安', '南京', '杭州', '成都', '重庆', '郑州'],
      ityList: city, // 城市数组
      end_time: '',
      currentDate: new Date(),
      timeshow: false,
      datalist: [],

      // 请求数据
      loading: false, // 控制上拉加载的加载动画
      finished: false, // 控制在页面往下移动到底部时是否调用接口获取数据
      totalPage: 0,
      pageNumber: 0, // 自定义一个变量
      // -------------
      index: 1, // 选中的时间
      datetime: [] // 定义一个时间数组

    }
  },

  mounted () {
    this.onLoad()
    this.clientHeight = `${document.documentElement.clientHeight}` // document.body.clientWidth;
    this.$refs.homePage.style.minHeight = this.clientHeight + 'px'
    // this.addDate(); //获取时间
    if (sessionStorage.getItem("city")) {
      this.current = sessionStorage.getItem("city")
    } else {
      this.mapinit()
    } // 定位
    // this.timedata();
  },
  methods: {

    // ---------------------------------------------------
    mapinit () { // 定位
      let that = this
      let map = new AMap.Map('container', {
        enableHighAccuracy: true,
        resizeEnable: true,
        center: [114.085947, 22.547],
        zoom: 8
      })
      // document.getElementById('adcode').innerHTML = '当前城市adcode：' + map.getAdcode() + '<br>' +
      //   '当前中心点：' + map.getCenter()
      // 获取用户所在城市信息
      function showCityInfo () {
        // 实例化城市查询类
        let citysearch = new AMap.CitySearch()
        // 自动获取用户IP，返回当前城市
        citysearch.getLocalCity(function (status, result) {
          // console.log(result)
          if (status === 'complete' && result.info === 'OK') {
            if (result && result.city && result.bounds) {
              // console.log(JSON.stringify(result));
              let cityinfo = result.city
              let citybounds = result.bounds
              that.chengshi = cityinfo
              that.current = cityinfo
              // document.getElementById('info').innerHTML = '您当前所在城市：' + cityinfo;
              // 地图显示当前城市
              map.setBounds(citybounds)
            }
          } else {
            // document.getElementById('info').innerHTML = result.info;
            // console.log(result)
          }
        })
      }
      showCityInfo()
    },
    onLoad () {
      let self = this
      // let mylan = this.lan + ',' + this.lat
      // console.log(this.lan)
      setTimeout(() => {
        let data = {
          PageNo: self.pageNumber + 1,
          // MyLng: mylan, //经纬度
          Category: 4,
          City: this.popup_city, // 城市
          Name: this.search_value // 搜索
          // SortType: this.value1, //排序

        }
        resourceList(data).then(res => {
          console.log(res)
          self.totalPage = res.PageCount
          if (res.List.length > 0) {
            self.datalist = self.datalist.concat(res.List)
          } else {
            this.datalist = res.List
          }
          self.loading = false
          self.pageNumber++
          if (self.pageNumber >= self.totalPage) {
            self.finished = true
          }
        })
      }, 500)
    },
    // 点击搜索
    issuecontent () {
      this.datalist = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
    },
    select () { // 打开选择城市
      this.show = true
    },
    cell (e) { // 选择城市
      this.current = e
      this.show = false
      this.datalist = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
      // console.log(e)
      // console.log(this.chengshi)
    },
    popularCs (e) { // 选择热门城市
      this.current = e
      this.show = false
      this.datalist = []
      this.pageNumber = 0
      this.onLoad()
      this.$forceUpdate()
      // console.log(e)
    },
    onClickLeft () { // 关闭选择城市
      this.show = false
    },

    Jumpbuy (resSN, title) {
      this.$router.push({
        path: '/Hotel/productDetail',
        query: {
          resSN: resSN,
          title: title
        }
      })
    },
    clickleft () {
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="scss">
.excitingActivity {
  background: #ffffff;

  .bj {
    .van-icon {
      color: white !important;
    }
  }

  .van-popup {
    .van-nav-bar {
      .van-icon {
        color: white !important;
      }
    }
  }

  .search {
    width: 94%;
    margin: 0 auto;
    display: flex;
    background: white;
    height: 3.125rem;
    border: 0.0625rem solid #00cba6;
    border-radius: 30px;

    .search_cs {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 90px;
    }

    .search_in {
      display: flex;
      align-items: center;
      width: 60%;

      .van-search {
        padding: 0 !important;
        background: #ffffff;

        .van-search__content {
          background: none;

          .van-cell {
            border-left: 1px solid rgb(225, 225, 225);
            padding: 0px 0px 0px 10px;
            background: none;

            input {
              background: none;
            }
          }
        }
      }
    }
  }

  .time_content {
    display: flex;
    justify-content: space-around;
    width: 100%;
    height: 5rem;

    // .time_active {
    //   border: 0.05rem solid red !important;
    // }

    .time {
      display: flex;
      flex-direction: column;
      width: 18%;
      height: 100%;
      align-items: center;
      justify-content: center;
      border: 1px solid #a09696b8;
      color: #a09696b8;

      .calendar {
        position: relative;
        width: 100%;
        height: 100%;
        z-index: 100;

        .selectedDate {
          span {
            opacity: 0;
          }
        }
      }
    }

    .active {
      border: 1px solid #46d0ca;
      color: #46d0ca;
    }
  }

  .current {
    display: flex;
    padding: 0.625rem 1rem;
    line-height: 2rem;
    font-size: 1.125rem;
    background: #ffffff;
    justify-content: space-between;
    color: #999999;

    .current_box {
      width: 50%;
      display: flex;
      justify-content: space-around;
    }
  }

  .popular {
    .popular_p {
      padding: 10px 16px;
      background: #f5f5f5;
      font-size: 1.1rem;
    }

    .popular_cs {
      width: 80px;
      height: 30px;
      margin: 0.625rem 0.625rem;
      border-radius: 1.875rem;
      border: 1px solid #e4e4e4;
      display: flex;
      font-size: 1rem;
      align-items: center;
      justify-content: center;
    }
  }

  .van-index-bar {
    color: #999999 !important;

    .van-index-anchor {
      background: #f5f5f5;
      color: #999999 !important;
      font-weight: 600;
    }

    .van-cell {
      color: #999999 !important;
    }
  }

  .van-popup {
    // top: 0;
    // transform:translate3d(0,0%,0) !important;
    .van-nav-bar {
      .van-nav-bar__left {
        // .van-icon {
        //   font-size: 22px;
        //   color: #46d0ca !important;
        // }
      }
    }
  }

  .van-tabs {
    .van-tabs__wrap {
      .van-tabs__nav {
        .van-tabs__line {
          background-color: #46d0ca;
        }
      }
    }
  }

  .calendar {
    height: 100%;
    display: flex;
    align-items: center;
  }

  .list {
    padding: 0 0.4375rem;
    background-color: #ffffff;
    overflow: hidden;
    position: relative;

    .performance-item {
      padding-top: 1.875rem;
      margin: 0 0.625rem;
      background: #ffffff;
      padding: 0.9375rem;
      margin-bottom: 0.625rem;
      display: flex;
      justify-content: space-between;

      .img-box {
        position: relative;
        justify-content: center;
        display: flex;
        width: 160px;
        height: 220px;
        align-items: center;
        overflow: hidden;
      }

      .info-box {
        width: 45%;
        color: #373737;
        position: relative;

        .title {
          font-size: 18px;
          margin-bottom: 0.625rem;
          max-height: 3.75rem;
          line-height: 22px;
          overflow: hidden;
          font-weight: 400;
        }

        .intro {
          //   font-size: 0.625rem;
          //   margin-bottom: 0.9375rem;
          //   line-height: 22px;
          //   height: 3.5rem;
          //   overflow: hidden;
          color: #5c5c5c;
        }

        .price {
          position: absolute;
          bottom: 40px;
          font-size: 24px;
          color: #46d0ca;
          text-align: left;
          font-weight: 600;
        }
      }
    }
  }
}
</style>
